# Maintainer: Andreas 'Segaja' Schleifer <segaja at archlinux dot org>

_gemname='ansi'
pkgname="ruby-${_gemname}"
pkgver=1.5.0
pkgrel=3
pkgdesc='Set of ANSI Code based classes and modules for Ruby'
arch=('any')
url="https://github.com/rubyworks/${_gemname}"
license=('BSD')
depends=('ruby')
checkdepends=('ruby-qed' 'ruby-ae' 'ruby-lemon' 'ruby-rubytest-cli')
options=('!emptydirs')
source=("${url}/archive/${pkgver}/${pkgname}-${pkgver}.tar.gz")
sha512sums=('42493d2fd0db738d71203cafd6ac1aad929760ad79174f7bb65f6b9853b5792db43596109dee2b818dc3ffdd167597a85061a40f7e2bdadd3ab833cbb4b42a14')

prepare() {
  cd "${_gemname}-${pkgver}"

  # update gemspec/Gemfile to allow newer version of the dependencies
  sed --in-place --regexp-extended 's|~>|>=|g' "${_gemname}.gemspec"

  sed -i 's/bundle exec //' Rakefile
}

build() {
  cd "${_gemname}-${pkgver}"

  gem build "${_gemname}.gemspec"
}


check() {
  cd "${_gemname}-${pkgver}"

  rake demo test 
}

package() {
  cd "${_gemname}-${pkgver}"

  local _gemdir="$(gem env gemdir)"

  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "${pkgdir}/${_gemdir}" \
    --bindir "${pkgdir}/usr/bin" \
    "${_gemname}-${pkgver}.gem"

  # remove unrepreducible files
  rm --force --recursive --verbose \
    "${pkgdir}/${_gemdir}/cache/" \
    "${pkgdir}/${_gemdir}/gems/${_gemname}-${pkgver}/vendor/" \
    "${pkgdir}/${_gemdir}/doc/${_gemname}-${pkgver}/ri/ext/"

  find "${pkgdir}/${_gemdir}/gems/" \
    -type f \
    \( \
      -iname "*.o" -o \
      -iname "*.c" -o \
      -iname "*.so" -o \
      -iname "*.time" -o \
      -iname "gem.build_complete" -o \
      -iname "Makefile" \
    \) \
    -delete

  find "${pkgdir}/${_gemdir}/extensions/" \
    -type f \
    \( \
      -iname "mkmf.log" -o \
      -iname "gem_make.out" \
    \) \
    -delete

  install --verbose -D --mode=0644 LICENSE.txt "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
  install --verbose -D --mode=0644 *.md --target-directory "${pkgdir}/usr/share/doc/${pkgname}"
}

# vim: set ts=2 sw=2 et:
